/**
 * BPMN.js 中文翻译
 */

const translations: Record<string, string> = {
  // 工具栏
  'Activate the global connect tool': '激活全局连接工具',
  'Activate the hand tool': '激活抓手工具',
  'Activate the lasso tool': '激活套索工具',
  'Activate the create/remove space tool': '激活创建/删除空间工具',
  'Create expanded SubProcess': '创建扩展子流程',
  'Create IntermediateThrowEvent/BoundaryEvent': '创建中间抛出事件/边界事件',
  'Create Pool/Participant': '创建池/参与者',
  'Create StartEvent': '创建开始事件',
  'Create EndEvent': '创建结束事件',
  'Create Gateway': '创建网关',
  'Create Task': '创建任务',
  'Create DataObjectReference': '创建数据对象引用',
  'Create DataStoreReference': '创建数据存储引用',
  'Create Group': '创建组',

  // 元素类型
  'Start Event': '开始事件',
  'End Event': '结束事件',
  'Intermediate Throw Event': '中间抛出事件',
  'Intermediate Catch Event': '中间捕获事件',
  'Boundary Event': '边界事件',
  Task: '任务',
  'User Task': '用户任务',
  'Service Task': '服务任务',
  'Script Task': '脚本任务',
  'Business Rule Task': '业务规则任务',
  'Manual Task': '手工任务',
  'Send Task': '发送任务',
  'Receive Task': '接收任务',
  'Call Activity': '调用活动',
  'Sub Process': '子流程',
  'Event Sub Process': '事件子流程',
  Transaction: '事务',
  'Exclusive Gateway': '排他网关',
  'Parallel Gateway': '并行网关',
  'Inclusive Gateway': '包容网关',
  'Complex Gateway': '复杂网关',
  'Event based Gateway': '事件网关',
  'Sequence Flow': '顺序流',
  'Message Flow': '消息流',
  Association: '关联',
  'Data Input Association': '数据输入关联',
  'Data Output Association': '数据输出关联',
  Pool: '池',
  Lane: '泳道',
  Participant: '参与者',
  'Expanded Pool': '扩展池',
  'Collapsed Pool': '折叠池',
  'Data Object Reference': '数据对象引用',
  'Data Store Reference': '数据存储引用',
  Group: '组',
  'Text Annotation': '文本注释',

  // 右键菜单
  'Append Task': '追加任务',
  'Append EndEvent': '追加结束事件',
  'Append Gateway': '追加网关',
  'Append Intermediate/Boundary Event': '追加中间/边界事件',
  'Append TextAnnotation': '追加文本注释',
  'Change type': '修改类型',
  'Connect using Association': '使用关联连接',
  'Connect using Sequence/MessageFlow': '使用顺序流/消息流连接',
  'Connect using DataInputAssociation': '使用数据输入关联连接',
  Remove: '删除',
  Delete: '删除',
  'Replace with expanded SubProcess': '替换为扩展子流程',
  'Replace with collapsed SubProcess': '替换为折叠子流程',
  'Replace with EventSubProcess': '替换为事件子流程',
  'Replace with Transaction': '替换为事务',

  // 编辑操作
  Undo: '撤销',
  Redo: '重做',
  Copy: '复制',
  Paste: '粘贴',
  Cut: '剪切',
  'Select All': '全选',
  'Zoom In': '放大',
  'Zoom Out': '缩小',
  'Zoom to Fit': '适应画布',
  'Reset Zoom': '重置缩放',

  // 属性面板
  Id: 'ID',
  Name: '名称',
  General: '常规',
  Details: '详情',
  Documentation: '文档',
  'Element Documentation': '元素文档',
  'Process Documentation': '流程文档',
  Executable: '可执行',
  'Execution Listener': '执行监听器',
  'Task Listener': '任务监听器',
  Extensions: '扩展',
  'Input/Output': '输入/输出',
  Connector: '连接器',
  'Field Injection': '字段注入',
  Forms: '表单',
  Listeners: '监听器',
  History: '历史',
  'Job Configuration': '作业配置',
  'External Task Configuration': '外部任务配置',
  'Candidate Configuration': '候选配置',
  'Multi Instance': '多实例',

  // 错误提示
  'no parent for {element} in {parent}':
    '在 {parent} 中没有 {element} 的父元素',
  'no shape type specified': '未指定形状类型',
  'flow elements must be children of pools/participants':
    '流元素必须是池/参与者的子元素',
  'out of bounds release': '超出边界释放',
  'more than {count} child lanes': '超过 {count} 个子泳道',
  'element required': '元素必填',
  'diagram not part of bpmn:Definitions': '图表不是 bpmn:Definitions 的一部分',
  'no diagram to display': '没有可显示的图表',
  'no process or collaboration to display': '没有可显示的流程或协作',
  'element {element} referenced by {referenced}#{property} not yet drawn':
    '元素 {element} 被 {referenced}#{property} 引用但尚未绘制',
  'failed to import {element}': '导入 {element} 失败',

  // 其他
  Append: '追加',
  'Add Lane above': '在上方添加泳道',
  'Add Lane below': '在下方添加泳道',
  'Divide into two Lanes': '分成两个泳道',
  'Divide into three Lanes': '分成三个泳道',
  Replace: '替换',
  'Replace with': '替换为',
  'Replace with None Start Event': '替换为空开始事件',
  'Replace with Message Start Event': '替换为消息开始事件',
  'Replace with Timer Start Event': '替换为定时开始事件',
  'Replace with Conditional Start Event': '替换为条件开始事件',
  'Replace with Signal Start Event': '替换为信号开始事件',
  'Replace with None End Event': '替换为空结束事件',
  'Replace with Message End Event': '替换为消息结束事件',
  'Replace with Escalation End Event': '替换为升级结束事件',
  'Replace with Error End Event': '替换为错误结束事件',
  'Replace with Cancel End Event': '替换为取消结束事件',
  'Replace with Compensation End Event': '替换为补偿结束事件',
  'Replace with Signal End Event': '替换为信号结束事件',
  'Replace with Terminate End Event': '替换为终止结束事件',
  'Replace with None Intermediate Throw Event': '替换为空中间抛出事件',
  'Replace with Message Intermediate Throw Event': '替换为消息中间抛出事件',
  'Replace with Escalation Intermediate Throw Event': '替换为升级中间抛出事件',
  'Replace with Link Intermediate Throw Event': '替换为链接中间抛出事件',
  'Replace with Compensation Intermediate Throw Event':
    '替换为补偿中间抛出事件',
  'Replace with Signal Intermediate Throw Event': '替换为信号中间抛出事件',
  'Replace with Message Intermediate Catch Event': '替换为消息中间捕获事件',
  'Replace with Timer Intermediate Catch Event': '替换为定时中间捕获事件',
  'Replace with Conditional Intermediate Catch Event': '替换为条件中间捕获事件',
  'Replace with Link Intermediate Catch Event': '替换为链接中间捕获事件',
  'Replace with Signal Intermediate Catch Event': '替换为信号中间捕获事件',
  'Replace with Message Boundary Event': '替换为消息边界事件',
  'Replace with Timer Boundary Event': '替换为定时边界事件',
  'Replace with Escalation Boundary Event': '替换为升级边界事件',
  'Replace with Conditional Boundary Event': '替换为条件边界事件',
  'Replace with Error Boundary Event': '替换为错误边界事件',
  'Replace with Cancel Boundary Event': '替换为取消边界事件',
  'Replace with Signal Boundary Event': '替换为信号边界事件',
  'Replace with Compensation Boundary Event': '替换为补偿边界事件',
  'Replace with User Task': '替换为用户任务',
  'Replace with Service Task': '替换为服务任务',
  'Replace with Script Task': '替换为脚本任务',
  'Replace with Business Rule Task': '替换为业务规则任务',
  'Replace with Manual Task': '替换为手工任务',
  'Replace with Send Task': '替换为发送任务',
  'Replace with Receive Task': '替换为接收任务',
  'Replace with Call Activity': '替换为调用活动',
  'Replace with Exclusive Gateway': '替换为排他网关',
  'Replace with Parallel Gateway': '替换为并行网关',
  'Replace with Inclusive Gateway': '替换为包容网关',
  'Replace with Complex Gateway': '替换为复杂网关',
  'Replace with Event based Gateway': '替换为事件网关',
  'Ad-hoc': '即席',
  'Parallel Multi Instance': '并行多实例',
  'Sequential Multi Instance': '顺序多实例',
  Loop: '循环',
  Compensation: '补偿',
  Collection: '集合',
  Conditional: '条件',
  Default: '默认',
  Message: '消息',
  Timer: '定时器',
  Error: '错误',
  Escalation: '升级',
  Link: '链接',
  Signal: '信号',
  Terminate: '终止',
  Cancel: '取消',
};

/**
 * 自定义翻译函数
 */
export default function customTranslate(
  template: string,
  replacements?: Record<string, string>,
): string {
  // 获取翻译
  let translation = translations[template] || template;

  // 替换占位符
  if (replacements) {
    Object.keys(replacements).forEach((key) => {
      translation = translation.replaceAll(
        new RegExp(`\\{${key}\\}`, 'g'),
        replacements[key],
      );
    });
  }

  return translation;
}
